home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / tjgold.zip / INSTALL.004 / FGUSER05.TXT < prev    next >
Text File  |  1995-05-29  |  28KB  |  675 lines

  1.  
  2.                           Mouse & Keyboard Management
  3.  
  4.                          "The ass loaded with gold still eats thistle"
  5.                                                      German proverb
  6.  
  7. Introduction
  8.  
  9.           The GOLDKEY unit contains all the mouse and keyboard
  10.      management routines needed to support sophisticated DOS
  11.      applications. The unit includes the following:
  12.  
  13.           - Functions which wait for user input by keyboard or mouse.
  14.           - Support for mouse double-clicks, as well as keyboard mouse
  15.             combinations such as Alt-Left Button.
  16.           - Routines to hide, display, confine and move the mouse
  17.             cursor.
  18.           - Routines to get and set the state of the toggle keys, e.g.
  19.             Caps Lock, Num Lock, etc.
  20.           - Procedures to stuff keystrokes and mouse actions in the
  21.             application's keyboard buffer.
  22.           - Support for user-defined call back functions.
  23.           - Routines to change the keyboard repeat rate.
  24.  
  25. What Did the User Press (or Click)?
  26.  
  27.           The primary purpose of GOLDKEY is to provide a flexible way to
  28.      pause for user mouse or keyboard activity and make it easy to then
  29.      find out what the user did! Gold uses three basic variables to
  30.      define a single user input: the keystroke or mouse action, the
  31.      mouse X coordinate and the mouse Y coordinate. These three
  32.      variables are defined in the KeyVars record as LastKey, LastX and
  33.      LastY. LastKey is a word-sized variable which is updated with a
  34.      number to indicate the key pressed. For example, if Lastkey has a
  35.      value of 27, the user pressed the Esc key, and if LastKey has a
  36.      value of 520, the user must have clicked the left mouse button. The
  37.      values in LastX and LastY indicate the location of the mouse cursor
  38.      when the button was clicked. Refer to the table on page 5-3 for a
  39.      complete list of the supported keystrokes and mouse clicks. TTT5
  40.      did not support a visible (free floating) mouse and life was much
  41.      simpler! In these good old days, keystrokes were defined in a
  42.      byte-sized variable. In Gold, a single keystroke or mouse action is
  43.      stored in a word-sized variable (KeyVars.LastKey). This change
  44.      allows a much wider range of keystrokes to be reported, and makes
  45.      Gold more flexible for international users.
  46.  
  47. Pausing for User Input
  48.  
  49.           At the heart of Gold's input management routines are the
  50.      GetInput and GetInputRel procedures. The GetInput procedure pauses
  51.      program execution and waits for the user to press a key combination
  52.      or press down a mouse button. As soon as the user has pressed a key
  53.      (combination) and pressed down a mouse button, the KeyVars.LastKey,
  54.      KeyVars.LastX and KeyVars.LastY variables are updated with the
  55.      appropriate values, and program execution continues. A important
  56.      point to note is that GetInput will return as soon as a mouse
  57.      button is pressed down. In other words, this function doesn't wait
  58.      for the user to release the mouse button. By responding immediately
  59.      to a mouse down, an application can implement "dragging support"
  60.      where some task has to be performed before the button is released.
  61.      Gold, for example, uses this procedure in the window dragging
  62.      routines. However, if you don't need to support any custom dragging
  63.      operations, call the GetInputRel procedure. This procedure is very
  64.      similar to GetInput, except that the procedure only returns from a
  65.      mouse click when the user has released the mouse button. With
  66.      respect to the keyboard, GetInput and GetInputRel are identical.
  67.      After calling GetInput or GetInputRel, the program should test the
  68.      value of KeyVars.LastKey to see what the user did. If the value is
  69.      mouse-related, the program should check the values of KeyVars.LastX
  70.      and KeyVars.LastY to see where the mouse cursor was when the button
  71.      was clicked.
  72.  
  73.           The following table details all the codes returned in
  74.      KeyVars.LastKey:
  75.  
  76.  
  77. Keyboard codes
  78.  
  79.      ╔═════════════════════════════╦═════════════════════════════╗
  80.      ║ Key   Norm  Shft  Alt  Ctrl ║ Key   Norm  Shft  Alt  Ctrl ║
  81.      ╠═════════════════════════════╬═════════════════════════════╣
  82.      ║  a     97    65   286    1  ║ F1     315   340  260   350 ║
  83.      ║  b     98    66   304    2  ║ F2     316   341  361   351 ║
  84.      ║  c     99    67   302    3  ║ F3     317   342  362   352 ║
  85.      ║  d     100   68   288    4  ║ F4     318   343  363   353 ║
  86.      ║  e     101   69   274    5  ║ F5     319   344  364   354 ║
  87.      ║  f     102   70   289    6  ║ F6     320   345  365   355 ║
  88.      ║  g     103   71   290    7  ║ F7     321   346  366   356 ║
  89.      ║  h     104   72   291    8  ║ F8     322   347  367   357 ║
  90.      ║  i     105   73   279    9  ║ F9     323   348  368   358 ║
  91.      ║  j     106   74   292   10  ║ F10    324   349  369   359 ║
  92.      ║  k     107   75   293   11  ║ F11    389   391  395   393 ║
  93.      ║  l     208   76   294   12  ║ F12    390   392  396   394 ║
  94.      ║  m     109   77   306   13  ║ Enter   13    13  284    10 ║
  95.      ║  n     110   78   305   14  ║ BkSp     8     8  270   127 ║
  96.      ║  o     111   79   280   15  ║ Up     328   428  408   397 ║
  97.      ║  p     112   80   281   16  ║ Down   336   436  416   401 ║
  98.      ║  q     113   81   272   17  ║ Left   331   431  411   371 ║
  99.      ║  r     114   82   275   18  ║ Right  333   433  413   372 ║
  100.      ║  s     115   83   287   19  ║ End    335   435  415   373 ║
  101.      ║  t     116   84   276   20  ║ Home   327   427  407   375 ║
  102.      ║  u     117   85   278   21  ║ PgUp   329   429  409   388 ║
  103.      ║  v     118   86   303   22  ║ PgDn   337   437  417   374 ║
  104.      ║  w     119   87   273   23  ║ Ins    338   261  418   260 ║
  105.      ║  x     120   88   301   24  ║ Del    339   263  419   262 ║
  106.      ║  y     121   89   277   25  ║ Tab      9   271  421   404 ║
  107.      ║  z     122   90   300   26  ║ Esc     27    27  257    27 ║
  108.      ║  1 !   49    33   376       ║ , <     44    60  307       ║
  109.      ║  2 @   50    64   377   259 ║ . >     46    62  308       ║
  110.      ║  3 #   51    35   378       ║ / ?     47    63  309       ║
  111.      ║  4 $   52    36   379       ║ ; :     59    58  295       ║
  112.      ║  5 %   53    37   380       ║ ' "     39    34  296       ║
  113.      ║  6 ^   54    94   381   30  ║ [ {     91   123  282    27 ║
  114.      ║  7 &   55    38   382       ║ ] }     93   125  283    29 ║
  115.      ║  8 *   56    42   383       ║ \ |     92   124  299    28 ║
  116.      ║  9 (   57    40   384       ║                             ║
  117.      ║  0 )   48    41   385       ║                             ║
  118.      ║  - _   45    95   386   31  ║                             ║
  119.      ║  = +   61    43   387       ║                             ║
  120.      ╚═════════════════════════════╩═════════════════════════════╝
  121.  
  122. Mouse Codes
  123.  
  124.      Mouse Action            Code   Mouse Action           Code
  125.  
  126.      LeftMouseDown            500   LeftMouseClick          520
  127.      LeftMouseDown+Alt        501   LeftMouseClick+Alt      521
  128.      LeftMouseDown+Ctrl       502   LeftMouseClick+Ctrl     522
  129.      LeftMouseDown+Shift      503   LeftMouseClick+Shift    523
  130.      RightMouseDown           504   RightMouseClick         524
  131.      RightMouseDown+Alt       505   RightMouseClick+Alt     525
  132.      RightMouseDown+Ctrl      506   RightMouseClick+Ctrl    526
  133.      RightMouseDown+Shift     507   RightMouseClick+Shift   527
  134.      CenterMouseDown          508   CenterMouseClick        528
  135.      CenterMouseDown+Alt      509   CenterMouseClick+Alt    529
  136.      CenterMouseDown+Ctrl     510   CenterMouseClick+Ctrl   530
  137.      CenterMouseDown+Shift    511   CenterMouseClick+Shift  531
  138.  
  139.      LeftMouseDoubleClick     540   LeftDoubleClickonList   560
  140.      RightMouseDoubleClick    544
  141.      CenterMouseDoubleClick   548
  142.  
  143. Window Codes
  144.  
  145.      Window Action                       Code
  146.  
  147.      Close icon selected                  600
  148.      Window moved or dragged              601
  149.      Window zoomed or stretched           602
  150.      Up arrow on V scrollbar selected     610
  151.      Down arrow on V scrollbar selected   611
  152.      Left arrow on H scrollbar selected   612
  153.      Right arrow on H scrollbar selected  613
  154.      Click on body of V scrollbar         614
  155.      Clicked on body of H scrollbar       615
  156.  
  157.           Refer to Chapter 4 for a full explanation of the window codes,
  158.      and when they are generated.
  159.  
  160.           Run the demo program DEMKY1.PAS to interactively see the key
  161.      codes used by Gold.
  162.  
  163. A Basic Input Loop
  164.  
  165.           The following program fragment illustrates a basic input loop
  166.      which pauses for user input and then calls an appropriate
  167.      subroutine:
  168.  
  169.      Finished := false
  170.      repeat
  171.         GetInputRel;
  172.         case KeyVars.LastKey of
  173.            301,113,81: Finished := true;  {Alt-X,q,Q}
  174.            315: HelpEm;  {F1}
  175.            337: ScrollDown20;  {PgDn}
  176.            329: ScrollUp20;    {PgUp}
  177.            287: SaveIt;  {Alt-S}
  178.            520: begin    {Left button click}
  179.               if (KeyVars.LastX <= 10)
  180.               and (KeyVars.LastY = HardVars.Depth) then
  181.                  Finished := true;
  182.            end;
  183.         end;
  184.      until Finished;
  185.  
  186. Ignoring the Mouse
  187.  
  188.           If you are not interested in mouse activity and want to wait
  189.      for the user to hit a standard key or key combination, you can use
  190.      the function GetKey which is defined as follows:
  191.  
  192.      GetKey:char;
  193.  
  194.           Waits for the user to press a key or key combination which has
  195.      a value in the range 13 to 255. The function returns the character
  196.      value of the input. Mouse activity is ignored. Behind the scenes,
  197.      GetKey uses GetInput and so the KeyVars variables LastKey, LastX
  198.      and LastY are updated.
  199.  
  200. Setting the Maximum Wait Time for Input
  201.  
  202.           Gold includes the procedure GetInputWait to allow programs to
  203.      run with or without user input, and is defined as follows:
  204.  
  205.      GetInputWait(WaitTime:longint);
  206.  
  207.           Waits for user input via the mouse or keyboard. GetInputWait
  208.      is very similar to GetInput, except that a maximum wait time is
  209.      specified in milliseconds. The user input is recorded in the
  210.      KeyVars variables LastKey, LastX and LastY. If WaitTime expires
  211.      before user input is received, the procedure terminates and LastKey
  212.      is set to zero. If a wait time of zero is specified, GetInputWait
  213.      will not time out, i.e. it will wait indefinitely for user input.
  214.  
  215. Controlling and Managing the Mouse
  216.  
  217.           Gold makes extensive use of the mouse in everything from menus
  218.      to input forms. As a developer, you gain all this power without
  219.      having to write any mouse-specific code. However, if you want to
  220.      write some custom routines which need to access the mouse, you can
  221.      take advantage of the following mouse routines:
  222.  
  223.      MouseInstalled:boolean;
  224.  
  225.           Returns TRUE if a mouse and mouse driver are installed,
  226.      otherwise FALSE is returned.
  227.  
  228.      MouseHardwareReset;
  229.  
  230.           Uses a hardware interrupt to reset the mouse to its standard
  231.      defaults. In 99% of hardware setups, a software reset (discussed
  232.      next) is faster and has the same effect.
  233.  
  234.      MouseSoftwareReset;
  235.  
  236.           Uses a software interrupt to set the mouse to its default
  237.      configuration. This function is called automatically when a program
  238.      (which uses GOLDKEY) is started.
  239.  
  240.      MouseShow(On:boolean);
  241.  
  242.           When passed TRUE, the mouse is made visible, otherwise the
  243.      mouse is hidden.
  244.  
  245.      MouseMove(X,Y: integer);
  246.  
  247.           Moves the mouse to the specified (X,Y) coordinate. Note that
  248.      local window or screen coordinates have no effect on this procedure
  249.      -- coordinates are always treated as global.
  250.  
  251.      MouseConfine(X1,Y1,X2,Y2:integer);
  252.  
  253.           Defines a rectangular region of the screen where the mouse can
  254.      move -- the user will not be able to move the mouse cursor beyond
  255.      the specified region.
  256.  
  257.      MousePos(var X,Y: byte);
  258.  
  259.           Updates the passed parameters with the current location of the
  260.      mouse cursor. Note that local window or screen coordinates have no
  261.      effect on this procedure -- coordinates are always reported as
  262.      globals.
  263.  
  264.      MouseReleased(Button: integer; var X,Y: byte): byte;
  265.  
  266.           Returns the number of times the specified button has been
  267.      released since the function was last called. Button values of 0, 1
  268.      and 2 represent the left, right and middle buttons, respectively.
  269.      The variables X and Y are updated with the mouse cursor coordinates
  270.      the last time the button was released.
  271.  
  272.      MousePressed(Button: integer; var X,Y: byte): byte;
  273.  
  274.           Returns the number of times the specified button has been
  275.      pressed since the function was last called. Button values of 0, 1
  276.      and 2 represent the left, right and middle buttons, respectively.
  277.      The variables X and Y are updated with the mouse cursor coordinates
  278.      the last time the button was pressed.
  279.  
  280.      MouseInZone(X1,Y1,X2,Y2: byte):boolean;
  281.  
  282.           Returns TRUE if the mouse cursor is situated within the
  283.      specified global coordinates.
  284.  
  285.      MouseStatus(var L,C,R:boolean; var X,Y : byte);
  286.  
  287.           Updates the L, C and R boolean variables to TRUE if any of the
  288.      left, center or right buttons are depressed, and updates the
  289.      variables X and Y with the current mouse location.
  290.  
  291.      MouseStatusWin(var L,C,R: boolean; var X,Y: byte);
  292.  
  293.           Operates like MouseStatus, except that the X and Y coordinates
  294.      are local to the window with focus.
  295.  
  296.      MouseStyle(OrdChar,Attr: byte);
  297.  
  298.           Sets the mouse cursor to the character represented by the
  299.      ASCII value OrdChar. The second parameter controls the display
  300.      attribute of the mouse cursor. If a zero is specified, Gold uses
  301.      the standard mouse device driver technique, which changes color
  302.      based on the underlying screen attribute to ensure maximum
  303.      contrast.
  304.  
  305.      MouseRelease;
  306.  
  307.           Waits for all mouse buttons to be released.
  308.  
  309.      Run the demo program DEMKY2.PAS to see the mouse routines in
  310.      action.
  311.  
  312. Mouse-Related Elements of KeyVars
  313.  
  314.           The following elements of the global record KeyVars affect the
  315.      mouse functions:
  316.  
  317. MouseActive
  318.  
  319.           The variable KeyVars.MouseActive is set to TRUE (at program
  320.      start-up) if a mouse is installed. Gold can be forced to ignore the
  321.      mouse by setting this variable to FALSE.
  322.  
  323. DoubleDelay
  324.  
  325.           Gold has to differentiate between two single clicks of the
  326.      mouse and one double click. To use an old gag, the difference is
  327.      "timing". If two single mouse clicks occur within a specified
  328.      (short) time period, a single click and a double click are
  329.      returned. The variable KeyVars.DoubleDelay specifies, in
  330.      milliseconds, the maximum elapsed time allowed between two mouse
  331.      clicks if the second click is to be reported as a double click. The
  332.      default is 350. This variable can be changed as desired.
  333.  
  334. RightHanded
  335.  
  336.           The de facto standard in the industry is for the left mouse
  337.      button to be the "do it" or "enter" button, and this is Gold's
  338.      default. By setting the variable KeyVars.RightHanded to TRUE, an
  339.      application will behave as though the right mouse button is the
  340.      do-it button. If your code is written with the left mouse codes as
  341.      the standard, a simple change to this variable is all that's needed
  342.      to give right button support.
  343.  
  344. InitScrollDelay, ScrollDelay
  345.  
  346.           When a user clicks on a scroll bar (in a window, list, form,
  347.      etc.) there is a momentary delay before scrolling occurs. The
  348.      variable KeyVars.InitScrollDelay sets the duration of the initial
  349.      delay, in milliseconds, and the variable KeyVars.ScrollDelay
  350.      controls the subsequent scrolling rate during scroll-bar
  351.      operations. The defaults are 350 and 50 respectively. These
  352.      variables can be changed as desired.
  353.  
  354. Accessing Ctrl, Alt and Shift
  355.  
  356.           GOLDKEY supports a wide variety of special key combinations
  357.      like Alt-Backspace and Ctrl-PgUp. Sometimes, however, you may want
  358.      to know if one of the shifting keys is being pressed on its own.
  359.      GetInput and GetInputWait will not respond when Ctrl, Alt or either
  360.      Shift key is pressed.
  361.  
  362.           GOLDKEY does, however, provide the following five functions to
  363.      let you check the status of the special shifting keys:
  364.  
  365.      KeyShiftPressed: boolean;
  366.  
  367.           Returns TRUE if either Shift key is being held down.
  368.  
  369.      KeyRightShiftPressed: boolean;
  370.  
  371.           Returns TRUE if the right Shift key is being held down.
  372.  
  373.      KeyLeftShiftPressed: boolean;
  374.  
  375.           Returns TRUE if the left Shift key is being held down.
  376.  
  377.      KeyCtrlPressed:boolean;
  378.  
  379.           Returns TRUE if a Ctrl key is being held down.
  380.  
  381.      KeyAltPressed:boolean;
  382.  
  383.           Returns TRUE if an Alt key is being held down.
  384.  
  385. Accessing Num, Scroll and Caps Lock
  386.  
  387.           GOLDKEY provides the following routines for determining and
  388.      changing the status of the Num Lock, Scroll Lock and Caps Lock
  389.      keys:
  390.  
  391.      KeyGetNum:boolean;
  392.  
  393.           Returns TRUE if the Num Lock key is on.
  394.  
  395.      KeyGetScroll:boolean;
  396.  
  397.           Returns TRUE if the Scroll Lock key is on.
  398.  
  399.      KeyGetCaps:boolean;
  400.  
  401.           Returns TRUE if the Caps Lock key is on.
  402.  
  403.      KeySetNum(On:boolean);
  404.  
  405.           Pass TRUE to turn on the Num Lock key, or FALSE to turn it
  406.      off.
  407.  
  408.      KeySetScroll(On:boolean);
  409.  
  410.           Pass TRUE to turn on the Scroll Lock key, or FALSE to turn it
  411.      off.
  412.  
  413.      KeySetCaps(On:boolean);
  414.  
  415.           Pass TRUE to turn on the Caps Lock key, or FALSE to turn it
  416.      off.
  417.  
  418.           Run the demo program DEMKY3.PAS to see how to access the
  419.      shifting and locking keys.
  420.  
  421. Setting the Keyboard Repeat Rate
  422.  
  423.           PC keyboards support a typematic effect, i.e. holding a key
  424.      pressed down has the same effect as pressing a key multiple times.
  425.      By default, a key must be held down for about half a second before
  426.      the repetition commences, and thereafter about ten characters per
  427.      second are sent. Most users think this repeat rate is too slow
  428.      (people west of Oklahoma excepted) and Gold provides a way of
  429.      changing it.
  430.  
  431.           The following three procedures alter the typematic rate on
  432.      systems with BIOS dated December 1985 or later:
  433.  
  434.      KeySetFast;
  435.  
  436.           Sets the typematic rate to 30 characters per second. This is
  437.      fast enough even for a New Yorker.
  438.  
  439.      KeySetSlow;
  440.  
  441.           Sets the typematic rate to 5 characters per second. This is
  442.      slow enough for the Post Office (just joking).
  443.  
  444.      KeySetRepeatRate(Delay,Rate:byte);
  445.  
  446.           This procedure allows you to explicitly set the typematic
  447.      rate. The first parameter accepts a value between 1 and 4 and
  448.      indicates the number of quarter seconds delay before the key
  449.      commences repeating. The second parameter indicates the repeat rate
  450.      and accepts a value between 0 and 31. The following table shows the
  451.      repeat rate parameter along with the resultant repeat rate:
  452.  
  453.       Val Rate  Val Rate  Val  Rate  Val  Rate  Val  Rate
  454.  
  455.       0   30.0  7   16.0  14   8.6   21   4.6   28   2.5
  456.       1   26.7  8   15.0  15   8.0   22   4.3   29   2.3
  457.       2   24.0  9   13.3  16   7.5   23   4.0   30   2.1
  458.       3   21.8  10  12.0  17   6.7   24   3.7   31   2.0
  459.       4   20.0  11  10.9  18   6.0   25   3.3
  460.       5   18.5  12  10.0  19   5.5   26   3.0
  461.       6   17.1  13   9.2  20   5.0   27   2.7
  462.  
  463.  
  464. Stuffing the Keyboard/Mouse Buffer
  465.  
  466.           GOLDKEY uses an internal buffer for storing keystrokes and
  467.      mouse clicks. The sole purpose of this buffer is to enable you to
  468.      force characters into the buffer using the KeyStuffBuffer...
  469.      procedures. The GetInput and GetInputWait functions check to see if
  470.      there any characters in the buffer before checking the physical
  471.      mouse and keyboard.
  472.  
  473.           By default the size of the buffer is 30 characters, but this
  474.      can easily be modified by changing the value of the
  475.      GStuffBufferSize constant at the top of the GOLDKEY.PAS file.
  476.  
  477.      Listed below is a description of the buffer-related procedures:
  478.  
  479.      KeyStuffBuffer(W:word);
  480.  
  481.           Adds a keystroke to the keyboard buffer. The parameter W is
  482.      the word value of the keystroke as detailed in the table starting
  483.      on page 6.3.
  484.  
  485.      KeyStuffBufferMouse(W:word;X,Y:byte);
  486.  
  487.           Use this function to add a mouse click to the keyboard buffer.
  488.      The W parameter identifies the mouse action and should be in the
  489.      range 520 to 560. X and Y identify the location of the mouse cursor
  490.      corresponding with the action.
  491.  
  492.      KeyStuffBufferStr(Str:string);
  493.  
  494.           Stuffs characters (with ASCII values in the range 0 to 255)
  495.      into the keyboard buffer. This procedure is provided as a
  496.      convenience to save making multiple calls to KeyStuffBuffer (one
  497.      call for every character in the string).
  498.  
  499.      KeyBufferSpace:word;
  500.  
  501.           Returns the amount of free space available in the keyboard
  502.      buffer. If the buffer is full, any attempt to stuff additional
  503.      keystrokes will be ignored.
  504.  
  505.      KeyFlushBuffer;
  506.  
  507.           Erases all the entries in the application's keyboard buffer.
  508.  
  509.      KeyFlushDOSBuffer;
  510.  
  511.           Erases all the entries in the DOS keyboard buffer.
  512.  
  513.           The keyboard buffer routines form the framework of a simple
  514.      but elegant macro facility. The demo file DEMKY5.PAS implements a
  515.      macro system and is discussed further in the (later) section Using
  516.      Keyboard Hooks.
  517.  
  518. Goodbye Keypress, Hello GkeyPressed
  519.  
  520.           The standard Borland Pascal function KeyPressed returns TRUE
  521.      if there is a character waiting in DOS's keyboard buffer. In a Gold
  522.      application, you should use GKeyPressed (for Gold KeyPressed)
  523.      instead. GKeyPressed checks the internal application keyboard
  524.      buffer as well as the DOS buffer. To parody Nike, "Just use it".
  525.  
  526.           If you want to check and see whether a key has been pressed,
  527.      or whether a mouse button is currently pressed, call the function
  528.      KeyorMousePressed. It functions like GkeyPressed but additionally
  529.      checks the state of the mouse buttons.
  530.  
  531. Using Keyboard Hooks
  532.  
  533.           Hooks provide a way for a developer to integrate custom
  534.      routines into the heart of Gold. GOLDKEY supports two primary types
  535.      of keyboard hooks. Gold can call a procedure while the program is
  536.      idle and waiting for the user to press a key; this type of hook is
  537.      known as an idle hook (or a Post Office hook). Similarly, you can
  538.      assign a procedure which will be called every time a character is
  539.      pressed or the mouse is clicked; this type of hook is known as a
  540.      pressed hook.
  541.  
  542. Using an Idle Hook
  543.  
  544.           An idle hook is an external procedure which is called
  545.      repeatedly while a program is waiting for the user to input data. A
  546.      good use for an idle hook is to display a clock, or to show the
  547.      status of the shifting keys.
  548.  
  549.           All you have to do is create a procedure following some
  550.      specific rules, and then call the procedure AssignIdleHook to
  551.      instruct Gold to call the procedure during idle time.
  552.  
  553.           For a procedure to be eligible as an idle hook it must adhere
  554.      to the following rules:
  555.  
  556.           The procedure must be declared as a far procedure at the root
  557.           level. Refer to section Understanding Hooks in Chapter 3 for
  558.           further information.
  559.  
  560.           The procedure must be declared with no (nada/zero/none) passed
  561.           parameters.
  562.  
  563.      The following procedure declaration follows these rules:
  564.  
  565.      {$F+}
  566.      procedure MyIdleHook;
  567.      begin
  568.         {some code}
  569.      end; {MyIdleHook}
  570.      {$F-}
  571.  
  572.           The following procedure is then called to instruct Gold to
  573.      call your procedure while the application is waiting for input:
  574.  
  575.      AssignIdleHook(Hook:KeyIdleHook);
  576.  
  577.           Instructs Gold to call the specified procedure while pausing
  578.      for user input.
  579.  
  580.           For example, the above procedure would be assigned with the
  581.      following statement:
  582.  
  583.      AssignIdleHook(MyIdleHook);
  584.  
  585.           The hooked procedure will be continually called while your
  586.      program is waiting for user input, so make sure that the procedure
  587.      is compact and doesn't consume too many clock cycles. If your
  588.      procedure involves too many tasks, the program will slow down
  589.      considerably during input. If you want to call an extended task,
  590.      like a background print program, you must continually checked the
  591.      GkeyPressed function and suspend your procedure when it returns
  592.      TRUE.
  593.  
  594.           If subsequently, you want to remove the idle hook, execute the
  595.      following:
  596.  
  597.      AssignIdleHook(NoKeyIdleHook);
  598.  
  599.           The demo file DEMKY4.PAS illustrates the use of an idle hook
  600.      to display a ticking clock.
  601.  
  602. Using a Pressed Hook
  603.  
  604.           A pressed hook is a procedure which is called every time a key
  605.      is pressed or a mouse button is clicked. The hooked procedure is
  606.      called before the key is processed, i.e. before the character is
  607.      returned by GetInput or GetInputWait. The hook is particularly
  608.      useful for trapping special keys like F1 for help, or for building
  609.      keyboard macros.
  610.  
  611.           All you have to do is create a procedure following some
  612.      specific rules, and then call the AssignPressedHook procedure to
  613.      instruct Gold to call your procedure every time a key is pressed.
  614.  
  615.           For a procedure to be eligible as a pressed hook it must
  616.      adhere to the following rules:
  617.  
  618.           The procedure must be declared as a far procedure at the root
  619.           level. Refer to the section Understanding Hooks in Chapter 3
  620.           for further information.
  621.  
  622.           The procedure must be declared with one variable parameter of
  623.           type word, and two variable parameters of type byte. These
  624.           parameters identify the user input, i.e. the Key, X and Y.
  625.  
  626.  
  627.      The following procedure declaration follows these rules:
  628.  
  629.      {$F+}
  630.      procedure MyPressedHook(var Code:word;var X,Y:byte);
  631.      begin
  632.         {some code}
  633.      end; {MyPressedHook}
  634.      {$F-}
  635.  
  636.           The following procedure is then called to instruct Gold to
  637.      call your procedure after each input:
  638.  
  639.      AssignPressedHook(Hook:KeyPressedHook);
  640.  
  641.           Instructs Gold to call the specified procedure before
  642.      processing each user input.
  643.  
  644.           If, subsequently, you want to remove the pressed hook, execute
  645.      the following:
  646.  
  647.      AssignPressedHook(NoKeyPressedHook);
  648.  
  649.           The demo file DEMKY5.PAS shows how a pressed hook can be used
  650.      to provide macro keyboard support.
  651.  
  652. Other Neat Stuff
  653.  
  654.           Here are a few more procedures included in GOLDKEY (we
  655.      couldn't decide where else to put them):
  656.  
  657.      ExtendedKeyBoard:boolean;
  658.  
  659.           Returns TRUE if the host system has an extended keyboard, i.e.
  660.      has 101 or more keys.
  661.  
  662.      KeySetClicking(Clicking : boolean);
  663.  
  664.           Call this procedure with a TRUE parameter if you want Gold to
  665.      make a tactile clicking noise every time a key is pressed, or pass
  666.      FALSE to turn off clicking.
  667.  
  668.      WordToChar(W:word):char;
  669.  
  670.           Gold uses a word-sized variable KeyVars.Lastkey to record user
  671.      input. Use this function translate the word-type keystroke to a
  672.      character. If the passed parameter is greater than 255, a #0 is
  673.      returned.
  674.  
  675.